package com.example.logistics_manage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.logistics_manage.pojo.Orders;
import com.example.logistics_manage.result.restful.R;
import com.example.logistics_manage.result.restful.ResponseEunm;
import com.example.logistics_manage.service.IOrderService;
import com.example.logistics_manage.service.serviceImpl.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orders")
@CrossOrigin
public class OrdersController {
    @Autowired
    IOrderService ordersService;

    /**
     * 分页查询订单
     * @param current 页数
     * @param size 每页大小
     * @return 页面数据
     */
    @GetMapping("/findAllQueryPage")
    public R<IPage<Orders>> findAllQueryPage(@RequestParam("current") Integer current,@RequestParam("size") Integer size){
        return new R<>(ResponseEunm.SUCCESS,ordersService.findAllQueryPage(current,size));
        
    }
    /**
     * 根据id找订单
     * @param orderId id
     * @return 订单
     */
    @GetMapping("/findOrdersById/{orderId}")
    public R<Orders> findOrdersById(@PathVariable("orderId") Integer orderId){
        return new R<>(ResponseEunm.SUCCESS,ordersService.findOrdersById(orderId));
    }
    /**
     * 更新订单
     * @param orders 订单
     */
    @PutMapping("/updateOrders")
    public R<Orders> updateOrders(@RequestBody Orders orders){
        if(ordersService.updateOrders(orders)!=1){
            return new R<>(ResponseEunm.UPDATE_FAIL,null);
        }
        return new R<>(ResponseEunm.SUCCESS,null);
    }
    /**
     * 删除订单
     * @param orderId 订单id
     * @return 布尔
     */
    @DeleteMapping("/deleteOrdersById/{orderId}")
    public R<Orders> deleteOrdersById(@PathVariable("orderId")Integer orderId){
        if (ordersService.deleteOrdersById(orderId)){
            return new R<>(ResponseEunm.SUCCESS,null);
        }else {
            return new R<>(ResponseEunm.DELETE_FAIL,null);
        }
    }
    /**
     * 范围查询
     * @param orders 1
     * @return 1
     */
    @PostMapping("/findOrdersByData")
    public R<IPage<Orders>> findOrdersByData(@RequestBody Orders orders,@RequestParam("current") Integer current,@RequestParam("size")Integer size){
       return new R<>(ResponseEunm.SUCCESS,ordersService.findOrdersByData(orders,current,size));
    }


}
